package top.xianggg.xservers.common.utils;

import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.SimpleHash;

/**
 * @author Jr.November
 */
public class PasswordUtils {

    /**
     * hash算法
     */
    private final static String ALGORITHM_NAME = "md5";
    /**
     * hash迭代次数
     */
    private final static int HASH_ITERATIONS = 2;

    /**
     * 获取随机盐
     */
    public static String randomSalt(String key) {
        return key + new SecureRandomNumberGenerator().nextBytes().toHex();
    }

    public static String hashPassword(String password, String salt) {
        return new SimpleHash(ALGORITHM_NAME, password, salt, HASH_ITERATIONS).toHex();
    }
}
